﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace devtm.Types
{

    /// <summary>
    /// Contient la liste des assemblies
    /// </summary>
    public class AssemblyDescriptionCollection : devtm.Collections.TableCollection<AssemblyName, string>
    {


        public AssemblyDescriptionCollection() : base(c => c.Name)
        {

            AssemblyCacheEnum e =new AssemblyCacheEnum(null);
            string name = e.GetNextAssembly();

            while (!string.IsNullOrEmpty(name))
            {

                AssemblyDescription a = new AssemblyDescription(name);

                if (!this.ContainsKey(a.AssemblyName))
                    this.Add(new AssemblyName() { Name = a.AssemblyName });

                AssemblyName b = this[a.AssemblyName];
                    
                b.Add(a);
                
                name = e.GetNextAssembly();
            }

        }


        /// <summary>
        /// retourne toutes les versions d'un assembly
        /// </summary>
        /// <param name="assemblyname"></param>
        /// <returns></returns>
        public bool ContainsAssembly(string assemblyname)
        {

            string name = assemblyname.Split(',')[0].Trim();

            if (this.ContainsKey(name))

                return true;

            return false;
        }


    }

}
